<?php
namespace App\Http\Logic;


class AccessTokenLogic extends BaseLogic
{
    public static function getAccessToken($user_info, $name)
    {
        $token = $user_info -> createToken($name);

        $token_id = $token -> accessToken -> id;

        $user_info -> tokens() -> where([['id', '<>', $token_id], ['name', $name]]) -> each(function ($token) {
            $token->delete();
        });

        return $token -> plainTextToken;
    }

    public static function delAccessToken($user_info)
    {
        $user_info -> tokens() -> delete();
    }
}
